// custom-tab-bar/index.js
import {
    storeBindingsBehavior
} from 'mobx-miniprogram-bindings'
import {
    store
} from '../store/store'

Component({
    behaviors: [storeBindingsBehavior],
    storeBindings: {
        store,
        fields: {
            userInfo: 'userInfo',
            active: 'activeTabBarIndex',
        },
        actions: {
            updateActive: 'updateActiveTabBarIndex'
        }
    },
    observers: {
        'userInfo': function (u) {
            this.setData({
                'list[1].info': u.id
            })
        }
    },
    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        list: [{
            "pagePath": "/pages/home2/home2",
            "text": "首页",
            "iconPath": "/image/tab/_ic_tabbar_home.png",
            "selectedIconPath": "/image/tab/_ic_tabbar_home_select.png"
        },
        {
            "pagePath": "/pages/market/list/list",
            "text": "逛逛",
            "iconPath": "/image/tab/_ic_tabbar_local.png",
            "selectedIconPath": "/image/tab/_ic_tabbar_local_select.png",
            "info": 0,
        },
        {
            "pagePath": "/pages/mine/mine",
            "text": "我的",
            "iconPath": "/image/tab/_ic_tabbar_me.png",
            "selectedIconPath": "/image/tab/_ic_tabbar_me_select.png"
        }
        ]
    },

    /**
     * 组件的方法列表
     */
    methods: {
        onChange(e) {
            this.updateActive(e.detail)
            wx.switchTab({
                url: this.data.list[e.detail].pagePath,
            })
        }
    }
})